/**
 * Created by baiguiren on 1/23/17.
 */

let async = require('async');

// create a queue object with concurrency 2
// priorityQueue小的优先级先执行
let q = async.priorityQueue(function (task, callback) {
  console.log('hello ' + task.name);
  callback();
}, 2);

// assign a callback
q.drain = function () {
  console.log('all items have been processed');
};

// add some items to the queue
q.push({name: 'foo'}, 10, function (err) {
  console.log('finished processing foo');
});
q.push({name: 'bar'}, 5, function (err) {
  console.log('finished processing bar');
});

// add some items to the queue (batch-wise)
q.push([{name: 'baz'}, {name: 'bay'}, {name: 'bax'}], 11, function (err) {
  console.log('finished processing item');
});

// add some items to the front of the queue
// q.unshift({name: 'bar'}, function (err) {
//   console.log('finished processing bar');
// });